package lv.dysnomia.server.entities;

import java.util.{ Date, List }
import javax.jdo.annotations.{ IdentityType, IdGeneratorStrategy, PersistenceCapable, Persistent, PrimaryKey }
import com.google.appengine.api.datastore.{ Key, Text }

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class Song {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  var key: Key = null

  @Persistent
  var title: String = null

  // Generate from title, but make unique, if it coincides with a totally different song
  // (label,version) has to be unique
  @Persistent
  var label: String = null

  // 1, 2, etc. (which version
  @Persistent
  var version: Int = 0

  @Persistent
  var created: Date = null

  @Persistent
  var userId: String = null

  @Persistent
  var lilypond: Lilypond = null

  @Persistent
  var lyrics: Text = null
  
  @Persistent
  var notes: Text = null
  
  @Persistent
  var pngLink: String = null
  
  @Persistent
  var svgLink: String = null
  
  @Persistent
  var midiLink: String = null
  
  @Persistent
  var oggLink: String = null
  
  def getKey():Key = key
  
  def setKey(key:Key):Unit = {
	  this.key = key
  }
  
  def getTitle():String = title
  
  def setTitle(title:String):Unit = {
	  this.title = title
  }
  
  def getLabel():String = label
  
  def setLabel(label:String):Unit = {
	  this.label = label
  }
  
  def getVersion():Int = version
  
  def setVersion(version:Int):Unit = {
	  this.version = version
  }
  
  def getCreated():Date = created
  
  def setCreated(created:Date):Unit = {
	  this.created = created
  }
  
  def getUserId():String = userId
  
  def setUserId(userId:String):Unit = {
	  this.userId = userId
  }
  
  def getLilypond():Lilypond = lilypond
  
  def setLilypond(lilypond:Lilypond):Unit = {
	  this.lilypond = lilypond
  }
  
  def getLyrics():Text = lyrics
  
  def setLyrics(lyrics:Text):Unit = {
	  this.lyrics = lyrics
  }
  
  def getNotes():Text = notes
  
  def setNotes(notes:Text):Unit = {
	  this.notes = notes
  }
  
  def getPngLink():String = pngLink
  
  def setPngLink(pngLink:String):Unit = {
	  this.pngLink = pngLink
  }
  
  def getSvgLink():String = svgLink
  
  def setSvgLink(svgLink:String): Unit = {
	  this.svgLink = svgLink
  }
  
  def getMidiLink():String = midiLink
  
  def setMidiLink(midiLink:String): Unit = {
	  this.midiLink = midiLink
  }
  
  def getOggLink():String = oggLink
  
  def setOggLink(oggLink:String): Unit = {
	  this.oggLink = oggLink
  }

  // Filtri: Valodas, Tēmas, Avoti, Žanri

  override def toString(): String = {
    val lyricsString: String = lyrics.getValue()
    label + "." + version + "(" + title + "): " + (if (lyricsString.length() > 24)
      lyricsString.substring(0, 21) + "..." else lyricsString)
  }
}
